package com.ysd.lis.controller.qi;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ysd.common.Result;
import com.ysd.lis.annotation.LogDetail;
import com.ysd.lis.aspect.OperationType;
import com.ysd.lis.controller.pub.BaseController;
import com.ysd.lis.entity.qi.QiIndexBusinessModule;
import com.ysd.lis.service.qi.QiIndexBusinessModuleService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 组件模块对照表 前端控制器
 * </p>
 *
 * @author WH
 * @since 2024-07-10
 */
@RestController
@RequestMapping("/api/qi/qiIndexBusinessModule")
public class QiIndexBusinessModuleController extends BaseController {

    @Autowired
    QiIndexBusinessModuleService qiIndexBusinessModuleService;

    @ApiOperation("查询")
    @GetMapping("/findBusinessModules")
    public Result findBusinessModules(QiIndexBusinessModule qiIndexBusinessModule) {

        LambdaQueryWrapper<QiIndexBusinessModule> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(StringUtils.isNotBlank(qiIndexBusinessModule.getModuleType()), QiIndexBusinessModule::getModuleType, qiIndexBusinessModule.getModuleType());
        lambdaQueryWrapper.like(StringUtils.isNotBlank(qiIndexBusinessModule.getTableName()), QiIndexBusinessModule::getTableName, qiIndexBusinessModule.getTableName());
        lambdaQueryWrapper.like(StringUtils.isNotBlank(qiIndexBusinessModule.getOutField()), QiIndexBusinessModule::getOutField, qiIndexBusinessModule.getOutField());
        lambdaQueryWrapper.eq(QiIndexBusinessModule::getDelFlag, 0);
        List<QiIndexBusinessModule> list = qiIndexBusinessModuleService.list(lambdaQueryWrapper);
        return Result.succ(list);
    }

    @ApiOperation("添加组件模块对照")
    @PostMapping("/addOrUpdateBusinessModules")
    public Result addOrUpdateBusinessModules(@RequestBody List<QiIndexBusinessModule> qiIndexBusinessModules) {
        qiIndexBusinessModuleService.saveOrUpdateBatch(qiIndexBusinessModules);
        return Result.succ("保存成功!");
    }

    @ApiOperation("删除组件模块对照")
    @GetMapping("/deleteBusinessModules")
    @LogDetail(requestParam = "deleteBusinessModules", operationType = OperationType.DELETE, module = "删除组件模块对照", content = "删除【moduleType】组件类型", businessName = "moduleType")
    public Result deleteQiIndexItem( QiIndexBusinessModule qiIndexBusinessModule) {
        boolean delete = qiIndexBusinessModuleService.removeById(qiIndexBusinessModule.getId());
        if (delete) {
            return Result.succ(1, "删除成功", null);
        } else {
            return Result.fail("删除失败");
        }
    }

    @ApiOperation("查询")
    @GetMapping("/getBusinessModuleAndData")
    public Result getBusinessModuleAndData(QiIndexBusinessModule pageParam){
        return qiIndexBusinessModuleService.getBusinessModuleAndData(pageParam);
    }

    @ApiOperation("查询")
    @GetMapping("/getMajorModuleAndData")
    public Result getMajorModuleAndData(QiIndexBusinessModule pageParam){
        return qiIndexBusinessModuleService.getMajorModuleAndData(pageParam);
    }

}
